unit uMPropList;

interface

uses
  Classes, TypInfo;

type
  TMPropList = class(TObject)
  private
    FPropCount: Integer;
    FPropList: PPropList;
  protected
    function GetPropName(aIndex: Integer): ShortString;
    function GetProp(aIndex: Integer): PPropInfo;
  public
    constructor Create(aObj: TPersistent);
    destructor Destroy; override;
    property PropCount: Integer read FPropCount;
    property PropNames[aIndex: Integer]: ShortString read GetPropName;
    property Props[aIndex: Integer]: PPropInfo read GetProp;
  end;

implementation

constructor TMPropList.Create(aObj: TPersistent);
begin
  FPropCount := GetTypeData(aObj.ClassInfo)^.PropCount;
  FPropList := nil;
  if FPropCount > 0 then
  begin
    GetMem(FPropList, FPropCount * SizeOf(Pointer));
    GetPropInfos(aObj.ClassInfo, FPropList);
  end;
end;

destructor TMPropList.Destroy;
begin
  if Assigned(FPropList) then
    FreeMem(FPropList);
  inherited;
end;

function TMPropList.GetProp(aIndex: Integer): PPropInfo;
begin
  Result := nil;
  if (Assigned(FPropList)) then
    Result := FPropList[aIndex];
end;

function TMPropList.GetPropName(aIndex: Integer): ShortString;
begin
  Result := GetProp(aIndex)^.Name;
end;

end.
